/**
 * @Author: SevDaisy十七散人 
 * @Date: 2020-07-14 19:10:01
 */
package zyy.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import zyy.util.BusinessException;
import zyy.util.Bus;

public class FrmNewPD extends JDialog implements ActionListener {
  private static final long serialVersionUID = 68741659025403864L;
  private JPanel text = new JPanel();
  private JPanel btns = new JPanel();
  private JLabel label = new JLabel("新建商品分类");
  private JTextField edt = new JTextField(20);
  private JButton commit = new JButton("提交");
  private JButton exit = new JButton("退出");

  public String PDname;

  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.commit) {
      this.PDname = this.edt.getText();
      if (this.PDname == null || this.PDname.equals("") || this.PDname.length() > 255) {
        JOptionPane.showMessageDialog(null, "商品目录名不可为空", "错误", JOptionPane.ERROR_MESSAGE);
      } else {
        {
          try {
            System.out.println("管理员 添加商品分类");
            Bus.Product_DirManager.add(this.PDname, Bus.fAdminMerchant.getCurrentMerchant().getMID());
            Bus.fAdminMerchant.reloadProduct_DirTable();
          } catch (BusinessException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
          }
        }
        this.setVisible(false);
      }
    } else if (e.getSource() == this.exit) {
      this.setVisible(false);
    }
  }

  public FrmNewPD() {
    // 基础 JDialog 设置
    {
      this.setTitle("外卖助手 管理员 新增商品目录");
      this.setSize(295, 145);
      this.setLocationRelativeTo(null);
      this.setVisible(true);
      Bus.fNewPD = this;
    }
    // this.getContentPane() 一级布局
    {
      this.getContentPane().setLayout(new BorderLayout());
      this.getContentPane().add(this.text, BorderLayout.CENTER);
      this.getContentPane().add(this.btns, BorderLayout.SOUTH);
    }
    // text 相关配置
    {
      this.text.setLayout(new FlowLayout(FlowLayout.LEFT));
      this.text.add(this.label);
      this.text.add(this.edt);
    }
    // btns 相关配置
    {
      this.btns.setLayout(new FlowLayout(FlowLayout.RIGHT));
      this.btns.add(this.commit);
      this.btns.add(this.exit);
      this.commit.addActionListener(this);
      this.exit.addActionListener(this);
      Bus.jButtonZYYStyle(this.commit);
      Bus.jButtonZYYStyle(this.exit);
    }
  }
}